// pages/account/report/report-list.js
const app = getApp()
const { wxPost, wxGet, commonShare, serviceBusy } = require('../../../utils/common.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    waitLoading: true,
    limit: 10,
    status: 0
  },
  onLoad: function (options) {
    this.refreshView = this.selectComponent("#refreshView")
    this.setData({ infoId: options.infoId||''})
    this.loadList()
  },
  loadList: function (append) {
    const that = this
    let start = append ? that.data.pageObj.nextIndex : 0
    let { status, limit ,infoId} = that.data
    let url = '/assetsInfo/adjustList'
    wx.showLoading({
      title: append ? '加载中...' : '请稍等...',
      mask: true
    })
    wxGet(url, { start, limit, status, infoId }, ({ data }) => {
      if (data.errorCode === 0) {
        let tempList = []
        if (append) {
          tempList = [...that.data.list, ...data.list]
        } else {
          tempList = data.list
        }
        that.setData({
          list: tempList,
          pageObj: data.pageObj
        })
      }
    }, null, () => {
      that.setData({
        waitLoading: false
      })
      wx.hideLoading()
      this.refreshView.stopPullRefresh()
    })
  },
  viewSuggest: function (e) {
    wx.navigateTo({
      url: `suggest?adjustId=${e.currentTarget.dataset.id}&infoId=${this.data.infoId}`
    })
  },
  switchTab(e) {
    const { status, id } = e.currentTarget.dataset
   
    if (status !== this.data.status) {
      wx.showLoading({
        title: '请稍等...',
        mask: true
      })
      this.setData({ status, start: 0, waitLoading: true, list: [], pageObj: {} })
      this.loadList()
    }
  },
  onShareAppMessage: function () {
    return commonShare()
  },
  loadMore: function (e) {
    const that = this
    if (that.data.pageObj.haxNextPage) {
      that.loadList(true)
    } else {
      that.setData({ noMore: true })
      // wx.showToast({
      //   title: '没有更多了',
      //   icon: 'none',
      //   duration: 2000
      // })
    }
  },
  //触摸开始
  handletouchstart: function (event) {
    this.refreshView.handletouchstart(event)
  },
  //触摸移动
  handletouchmove: function (event) {
    this.refreshView.handletouchmove(event)
  },
  //触摸结束
  handletouchend: function (event) {
    this.refreshView.handletouchend(event)
  },
  //触摸取消
  handletouchcancel: function (event) {
    this.refreshView.handletouchcancel(event)
  },
  //页面滚动
  onPageScroll: function (event) {
    this.refreshView.onPageScroll(event)
  },
  onPullDownRefresh: function () {
    this.loadList()
  }
})